// 四至 
const getLeft = (points) => {
    return Math.min(...points.map(t => t[0]))
}
export const getLeftPoints = (points) => {
    let leftX = getLeft(points)
    return points.filter(t => t[0] === leftX)[0]
}

const getRight = (points) => {
    return Math.max(...points.map(t => t[0]))
}
export const getRightPoints = (points) => {
    let rightX = getRight(points)
    return points.filter(t => t[0] === rightX)[0]
}

const getTop = (points) => {
    return Math.min(...points.map(t => t[1]))
}
export const getTopPoints = (points) => {
    let topY = getTop(points)
    return points.filter(t => t[1] === topY)[0]
}

const getBottom = (points) => {
    return Math.max(...points.map(t => t[1]))
}
export const getBottomPoints = (points) => {
    let bottomY = getBottom(points)
    return points.filter(t => t[1] === bottomY)[0]
}

export const getBoundingClientRect = (points) => {
    let bottom = getBottom(points),
        left = getLeft(points),
        top = getTop(points),
        right = getRight(points)
    return {
        bottom,
        left,
        top,
        right,
        width: Math.abs(left - right),
        height: Math.abs(top - bottom)
    }



    // bottom    :     689
    // height    :     649
    // left    :     0
    // right    :     576
    // top    :     40
    // width    :     576
    // x    :     0
    // y    :     40
}

export const getBoundingClientRectPoints = (points) => {
    let bottom = getBottomPoints(points),
        left = getLeftPoints(points),
        top = getTopPoints(points),
        right = getRightPoints(points)
    return {
        bottom,
        left,
        top,
        right,
        width: Math.abs(left[0] - right[0]),
        height: Math.abs(top[1] - bottom[1])
    }
}